package eao;

import java.util.List;

import javax.ejb.LocalBean;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import entity.Measure;

/**
 * Session Bean implementation class EaoMeasure
 */
@Stateless(mappedName = "eaoMeasure")
@LocalBean
public class EaoMeasure {

	@PersistenceContext
	private EntityManager em;
    /**
     * Default constructor. 
     */
    public EaoMeasure() {
        // TODO Auto-generated constructor stub
    }
    

    public Measure find(int id) {
        return em.find(Measure.class, id);
    }

    public List<Measure> list() {
    	return em.createQuery("SELECT m FROM Measure m", Measure.class).getResultList();
    }

    public void create(Measure measure) throws Exception {
        try{
        	em.persist(measure);
        	em.flush();
        }catch (Exception e) {
        	throw new Exception(e.getMessage());
		}
    }

    public void update(Measure measure) {
        em.merge(measure);
    }

    public void delete(Measure measure) {
        em.remove(em.contains(measure) ? measure : em.merge(measure));
    }

}
